import { HTTP } from "@/tools";
import { ApplicationClientType, ApplicationUseType, StandardQuery, StandardPagingResult, StandardResponse } from "./standard";
export interface GetSystemApplicationParam {
  code?: string,
  active?: boolean,
  name?: string
}
export interface SystemApplicationResultItem {
  active: boolean,
  code: string,
  createTime: string,
  createUser: number,
  id: number,
  name: string,
  status: number,
  updateTime: string,
  updateUser: number,
  userClient: string
}
/**
 * 主要用来设置下拉列表使用的
 * @param params 
 * @returns 
 */
export async function getSystemApplication(params?: Partial<GetSystemApplicationParam>) {
  return HTTP.post<StandardResponse<SystemApplicationResultItem[]>>('/sysApp/list', params)
}

export async function getSystemApplicationToSelectOpption(params?: Partial<GetSystemApplicationParam>) {
  return getSystemApplication(params).then(({ data: { data } }) => data.map(i => ({ label: i.name, value: i.code })))
}

export interface ApplicationSaveInfo {
  active: boolean,
  code: string,
  id?: number,
  name: string,
  sysType: ApplicationUseType,
  userClient: ApplicationClientType
}
/**
 * 保存系统应用信息
 * @param params 
 * @returns 
 */
export async function ApplicationInfoSave(params: ApplicationSaveInfo) {
  const { id } = params
  return HTTP.post(`/sysApp/${id ? 'edit' : 'add'}`, params)
}

export interface GetApplicationsParams extends Partial<ApplicationSaveInfo & StandardQuery> { }

/**
 * 分页查询结果列表项
 */
export interface ApplicationByPagingReusltItem extends ApplicationSaveInfo {
  id: number,
  updateTime: string,
  updateUser: number,
  createTime: string,
  createUser: number
}
/**
 * 分页查询应用列表
 * @param params 
 * @returns 
 */
export async function getApplicationByPaging(params: GetApplicationsParams) {
  return HTTP.post<StandardResponse<StandardPagingResult<ApplicationByPagingReusltItem>>>('/sysApp/page', params)
}

/**
 * 删除应用
 * @param id 
 * @returns 
 */
export async function ApplicationDelete(id: number) {
  return HTTP.post('/sysApp/delete', { id })

}
/**
 * 设置默认应用
 * @param id 
 * @returns 
 */
export async function setApplicationWithDefaultActive(id: number) {
  return HTTP.post('/sysApp/setAsDefault', { id })

}